package com.jiaoyou.baojian.adapter;

import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jiaoyou.baojian.R;
import com.jiaoyou.baojian.entity.GoodEntity;

/**
 * Created by DemonZYM on 17/4/13.
 */

public class GoodsAdapter extends BaseQuickAdapter<GoodEntity, BaseViewHolder> {

    private int selected = -1;

    public GoodsAdapter() {
        super(R.layout.item_good);
    }

    public void select(int position){
        selected = position;
    }

    public int getSelected(){
        return selected;
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodEntity item) {
        int position = helper.getAdapterPosition();
        TextView candy = helper.getView(R.id.candy);
        TextView dou = helper.getView(R.id.dou);
        TextView price = helper.getView(R.id.price);
        RelativeLayout background = helper.getView(R.id.background);
        candy.setText(item.getTitle());
        if(item.getPrice() >= 1){
            price.setText((int)item.getPrice() + " RMB");
        } else {
            price.setText(item.getPrice() + " RMB");
        }
        if(position == selected){
            candy.setTextColor(mContext.getResources().getColor(android.R.color.white));
            dou.setTextColor(mContext.getResources().getColor(android.R.color.white));
            price.setTextColor(mContext.getResources().getColor(android.R.color.white));
            background.setBackgroundColor(mContext.getResources().getColor(R.color.main_black_gray));
        } else {
            candy.setTextColor(mContext.getResources().getColor(R.color.main_black_gray));
            dou.setTextColor(mContext.getResources().getColor(R.color.main_black_gray));
            price.setTextColor(mContext.getResources().getColor(R.color.main_black_gray));
            background.setBackgroundColor(mContext.getResources().getColor(android.R.color.white));
        }
    }
}
